<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="renderer" content="webkit">
	    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<title>客户列表</title>
		<link rel="stylesheet" href="/Public/frame/layui/css/layui.css">
			<!--<link rel="stylesheet" href="http://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css">-->
		<link rel="stylesheet" href="/Public/frame/static/css/style.css">
	</head>
	<body>
		    <a href="<?php echo U('add',array('type'=>'customer'));?>"><button class="layui-btn" style="margin-top: 10px;"><i class="layui-icon">&#xe654;</i>添加客户</button></a>
        <a class="layui-btn btn-add btn-default" id="btn-refresh" style="margin-top: 10px;"><i class="layui-icon">&#x1002;</i></a>
      <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>搜索</legend>
      </fieldset>
      <form class="layui-form" id="search_form" action="/index.php/Hawk/Customer/lst" method="post">
      <div class="layui-form-item">           
        <div class="layui-inline">
          <label class="layui-form-label">部门</label>
          <div class="layui-input-inline">
            <select name="part_id" lay-filter="part_id" lay-verify="required" lay-search="">
              <option value="">直接选择或搜索选择</option>
<?php foreach ($list['part'] as $k => $v): if ($list['search']['part_id']==$v['id']) $select = 'selected = "selected"'; else $select = ''; ?>
              <option <?php echo ($select); ?> value="<?php echo ($v['id']); ?>"><?php echo ($v['name']); ?></option>
<?php endforeach;?>
            </select>
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">业务员</label>
          <div class="layui-input-inline">
            <select name="sale_worker" lay-filter="sale_worker" lay-verify="required" lay-search="">
              <option value="">直接选择或搜索选择</option>
<?php foreach ($list['sale_worker'] as $k => $v): if ($list['search']['sale_worker']==$v['id']) $select = 'selected = "selected"'; else $select = ''; ?>
              <option <?php echo ($select); ?> value="<?php echo ($v['id']); ?>"><?php echo ($v['nickname']); ?></option>
<?php endforeach;?>
            </select>
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">客户</label>
          <div class="layui-input-inline">
            <select name="cus_id" lay-filter="cus_id" lay-verify="required" lay-search="">
              <option value="">直接选择或搜索选择</option>
<?php foreach ($list['customer'] as $k => $v): if ($list['search']['cus_id']==$v['id']) $select = 'selected = "selected"'; else $select = ''; ?>
              <option <?php echo ($select); ?> value="<?php echo ($v['id']); ?>"><?php echo ($v['cusname']); ?></option>
<?php endforeach;?>
            </select>
          </div>
        </div>
        <div class="layui-inline">
          <label class="layui-form-label">时间</label>
          <div class="layui-input-inline" style="width: 100px;">
            <input type="text" name="time_start" lay-verify="required" id="date2"  autocomplete="off" class="layui-input" value="<?php echo ($list['search'][time_start]); ?>">
          </div>
          <div class="layui-form-mid">-</div>
          <div class="layui-input-inline" style="width: 100px;">
            <input type="text" name="time_end" lay-verify="required" id="date3"  autocomplete="off" class="layui-input" value="<?php echo ($list['search'][time_end]); ?>">
          </div>
        </div> 
        <div class="layui-inline">
        <div class="layui-input-inline">
         <button type="submit" class="layui-btn layui-btn-primary layui-btn-radius">搜 索</button>
       </div>
       </div>
      </div>
      </form>
      <fieldset class="layui-elem-field layui-field-title">
        <legend>客户列表</legend>
      </fieldset>
    	<table class="layui-table" border="" cellspacing="" cellpadding="" width="100%">
    		<thead>
    			<tr>
    				<td width="5%">序号</td>
            <td width="10%">单号</td>  
    				<td width="10%">订户姓名</td>
    				<td width="10%">消费金额</td>
    				<td width="5%">性别</td>
    				<td width="10%">订单资金</td>
    				<td width="10%">收单日期</td>
    				<td width="10%">服务到期日</td> 				
    				<td width="5%">详情</td>
    				<td width="25%">操作</td>
    			</tr>
    		</thead>
            <tbody>
<?php if(count($list['list']) > 0 ): foreach ($list['list'] as $k => $v):?>
            	<tr class="<?php echo $v['status']==1?'defriend':'';?>">
            		<td><?php echo $v['id'];?></td>
                <td><?php echo $v['odd_numbers'];?></td>
            		<td name="cusname"><?php echo $v['cusname'];?></td>
            		<td><input type="number" cid="<?php echo $v['id'];?>" id="consume" value="<?php echo $v['consume'];?>" /></td>
            		<td><?php echo $v['sex'];?></td>
            		<td><?php echo $v['allMoney'];?></td>
            		<td><?php echo $v['redate'];?></td>
            		<td><?php echo $v['server_time_end'];?></td>            		
            		<td><a  class="layui-btn layui-btn-mini more" cid="<?php echo $v['id']?>">更多信息</a></td>
            		<td>
                    <a  class="layui-btn layui-btn-mini money" cid="<?php echo $v['id']?>">资金操作</a>            		 
        					  <a href="<?php echo U('edit?id='.$v['id'].'&p='.I('get.p')); ?>" class="layui-btn layui-btn-mini" lay-event="edit">编辑</a>
        					  <a id="delete" s="<?php echo U('delete?id='.$v['id'].'&p='.I('get.p')); ?>" class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">删除</a>
                    <?php if ($v['is_checked']==0) { $class='check'; $word = '一审'; $color = 'layui-btn-danger'; }elseif($v['is_checked']==1){ $class='check'; $word = '二审'; $color = 'layui-btn-danger'; }elseif ($v['is_checked']==2) { $class='nopass'; $word = '未通'; $color = 'layui-btn-disabled'; }elseif ($v['is_checked']==6) { $class='pass'; $word = '一通'; $color = 'layui-btn-disabled'; }elseif ($v['is_checked']==7) { $class='pass'; $word = '二通'; $color = 'layui-btn-disabled'; }?>
                    <a class="layui-btn <?php echo ($color); ?> layui-btn-mini" id="<?php echo ($class); ?>" is_checked="<?php echo ($v['is_checked']); ?>" cus_id="<?php echo ($v['id']); ?>" lay-event="del"><?php echo ($word); ?></a>
            		</td>
            	</tr>
<?php endforeach;?> 
<?php if(preg_match('/\d/', $list['page'])): ?>  
        <tr><td align="right" nowrap="true" colspan="99" height="30" class="page"><?php echo $list['page']; ?></td></tr> 
<?php endif; ?> 
            </tbody>
<?php else: ?><tbody><tr><td align="center" nowrap="true" colspan="99" style="font-size:24px;padding:30px 0;">还无客户，继续努力吧！</td></tr></tbody><?php endif; ?>
    	</table>
	</body>
</html>
<script type="text/javascript" src="/Public/hawk/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="/Public/frame/layui/layui.js"></script>
    <script>
              // 刷新
        $('#btn-refresh').on('click', function () {
            document.getElementById("search_form").reset();
            location.reload();
        });
    layui.use(['layer','layedit', 'laydate'], function(){
          var layer = layui.layer
          ,layedit = layui.layedit
          ,laydate = layui.laydate;
          //日期选择
          laydate.render({
            elem: '#date2'
          });
          laydate.render({
            elem: '#date3'
          });
        //删除客户
        $(document).on('click','#delete',function(){
          if(confirm('是否删除客户-'+$('td[name=cusname]').html()+'？删除客户将删除客户所有相关信息，请慎重操作！！！！')){
            location.href=$(this).attr('s');
          }
        });
        //查看客户详情
        $(document).on('click','.more',function(){
            var cid=$(this).attr('cid');
            layer.open({
              type: 2,
              title:'客户详细信息',
              area: ['100%', '100%'],
              fixed: false, //不固定
              maxmin: true,
              content: '/index.php/Hawk/Customer/moreInfo/id/'+cid
            });
        });
        //调用资金操作页面
        $(document).on('click','.money',function(){
            var cid=$(this).attr('cid');
            layer.open({
              type: 2,
              title:'客户详细信息',
              area: ['70%', '70%'],
              fixed: false, //不固定
              maxmin: true,
              content: '/index.php/Hawk/Customer/moneyAdd/id/'+cid
            });
        });
        //ajax修改消费金额
        $(document).on('blur','#consume',function(){
          var cid=$(this).attr('cid');
          var money = $(this).val();
          layer.confirm('你是否要修改消费金额为'+money, {
            btn: ['确定','取消'] //按钮
          }, function(){
              $.post('/index.php/Hawk/Customer/consume',{'consume':money,'id':cid},function(data){
                var obj=eval('(' + data + ')');
                layer.msg(obj.msg);
              });
          })
        });
        //审核客户资料
        $(document).on('click','#check',function(){
            var is_checked=$(this).attr('is_checked');
            var cus_id = $(this).attr('cus_id');
            var $this=$(this);
            layer.confirm('审核中。。。', {
              title:'审核',
              btn: ['通过','不通过'] //按钮
            }, function(){
              $.post('/index.php/Hawk/Customer/check',{'is_checked':is_checked,'cus_id':cus_id,'type':1},function(data){
                  var obj=eval('(' + data + ')');
                  if(obj.code==1){
                    $this.attr('id','pass');
                    $this.attr('disabled','disabled');
                    if(is_checked==0){
                      $this.attr('is_checked',6);
                      $this.html('一通');
                      $this.removeClass('layui-btn-danger').addClass('layui-btn-disabled');
                    }else if(is_checked==1){
                      $this.attr('is_checked',7);
                      $this.html('二通');
                      $this.removeClass('layui-btn-danger').addClass('layui-btn-disabled');
                    }
                    layer.msg(obj.msg);
                  }else{
                    layer.msg(obj.msg);
                  }
              });
            }, function(){
              $.post('/index.php/Hawk/Customer/check',{'is_checked':is_checked,'cus_id':cus_id,'type':0},function(data){
                  var obj=eval('(' + data + ')');
                  if(obj.code==1){
                    if(is_checked==0){
                      $this.attr('is_checked',1);
                      $this.html('二审');
                    }else if(is_checked==1){
                      $this.attr('is_checked',2);
                      $this.attr('id','nopass');
                      $this.removeClass('layui-btn-danger').addClass('layui-btn-disabled');
                      $this.html('不通');
                    }
                    layer.msg(obj.msg);
                  }else{
                    layer.msg(obj.msg);
                  }
              });
            });
        });
        
    });
    
    </script>